using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace AutoUpdate
{
    public partial class FrmError : Form
    {
        private Exception m_Ex = null;
        private SqlException m_SQLEx = null;
        private InvalidOperationException m_InvOpEx = null;
        private DBConcurrencyException m_DBConEx = null;
        public FrmError(Exception ex)
        {
            InitializeComponent();
            m_Ex = ex;
        }
        public FrmError(SqlException ex)
        {
            InitializeComponent();
            m_SQLEx= ex;
        }
        public FrmError(InvalidOperationException ex)
        {
            InitializeComponent();
            m_InvOpEx = ex;
        }
        public FrmError(DBConcurrencyException ex)
        {
            InitializeComponent();
            m_DBConEx = ex;
        }
        private void FrmError_Load(object sender, EventArgs e)
        {
            if (m_SQLEx != null)
            {
                switch (m_SQLEx.Number)
                {
                    case 11001:
                        this.richTextBoxMessage.Text += "A aparut o eroare la stabilirea conexiunii cu serverul. \nDaca va conectati la SQL 2005 aceasta eroare poate fi cauzata de neacceptarea conexiunilor remote!\n\n" +
                            m_SQLEx.Message;
                        //this.listBox1.Items.Add("Nu adaugati in tabela randuri identificate de aceiasi cheie primara!");
                        this.listBox1.Items.Add(m_SQLEx.Source);
                        //this.DialogResult = DialogResult.Ignore;
                        break;
                    case 18487:
                        this.richTextBoxMessage.Text += "Parola dvs. a expirat. \nVa rugam contactati administratorul sistemului pentru actualizarea parolei!\n\n" +
                            m_SQLEx.Message;
                        //this.listBox1.Items.Add("Nu adaugati in tabela randuri identificate de aceiasi cheie primara!");
                        this.listBox1.Items.Add(m_SQLEx.Source);
                        //this.DialogResult = DialogResult.Ignore;
                        break;
                    case 18456:
                        this.richTextBoxMessage.Text += "Incercare esuata de intrare in sistem. Va rugam reincercati...!\n\n" +
                            m_SQLEx.Message;
                        //this.listBox1.Items.Add("Nu adaugati in tabela randuri identificate de aceiasi cheie primara!");
                        this.listBox1.Items.Add(m_SQLEx.Source);
                        //this.DialogResult = DialogResult.Ignore;
                        break;
                    default:
                        foreach (SqlError er in m_SQLEx.Errors)
                            this.richTextBoxMessage.Text += er.Message + "\n";

                        //this.richTextBoxMessage.Text = m_SQLEx.Message;
                        if (m_SQLEx.HelpLink != null)
                            this.listBox1.Items.Add(m_SQLEx.HelpLink.ToString());
                        this.listBox1.Items.Add("Server = " + m_SQLEx.Server);
                        this.listBox1.Items.Add("Sursa = " + m_SQLEx.Source);
                        this.listBox1.Items.Add("Procedura = " + m_SQLEx.Procedure);
                        this.listBox1.Items.Add("Cod Eroare = " + m_SQLEx.ErrorCode.ToString());
                        break;
                }

            }
            if (m_InvOpEx != null)
            {
                this.richTextBoxMessage.Text = m_InvOpEx.Message;
                if (m_InvOpEx.HelpLink != null)
                    this.listBox1.Items.Add(m_InvOpEx.HelpLink.ToString());

                this.listBox1.Items.Add("Sursa = " + m_InvOpEx.Source);

            }
            if (m_Ex != null)
            {
                this.richTextBoxMessage.Text = m_Ex.Message;
                if (m_Ex.HelpLink != null)
                    this.listBox1.Items.Add(m_Ex.HelpLink.ToString());

                this.listBox1.Items.Add("Sursa = " + m_Ex.Source);

            }
            if (m_DBConEx != null)
            {
                this.richTextBoxMessage.Text = m_DBConEx.Message;
                if (m_DBConEx.HelpLink != null)
                    this.listBox1.Items.Add(m_DBConEx.HelpLink.ToString());

                this.listBox1.Items.Add("Sursa = " + m_DBConEx.Source);

            }
        }

    }
}